<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统后台 - {$Think.config.INTENDANT_NAME} - by HemaCMS</title>
    <link href="__INTENDANT__/css/admin_style.css" rel="stylesheet" />
    <script src="__COMMON__/jquery.js"></script>
    <script src="__COMMON__/jquery.cookie.js"></script>
    <script src="__COMMON__/jquery.validate.min.js"></script> <!--表单验证-->
    <script src="__COMMON__/layer/layer.js"></script>
    <script src="__INTENDANT__/js/iteny.intendant.js"></script> <!--公共easyui JS-->
    <link href="__INTENDANT__/css/icons.css" rel="stylesheet" />
    <link href="__INTENDANT__/css/iteny.css" rel="stylesheet" />

</head>
<body>
<div class="wrap jj">
	<div class="nav">
	    <ul class="cc">
	        <li><a href="{:U('Site/menu')}">菜单设置</a></li>
	        <li class="current"><a href="{:U('Site/addMenu')}">添加菜单</a></li>
	    </ul>
	</div>
	<div class="common-form">
	    <form name="addMenu" method="post" class="J_ajaxForm" action="{:U('Site/addMenu')}">
	      <input type="hidden" name="addMenu" value="addMenu" />

	      <div class="table_list">
	      	<div class="h_a">菜单信息</div>
	        <table cellpadding="0" cellspacing="0" class="table_form" width="100%">
	          <tbody>
	            <tr>
	              <td width="140">上级菜单:</td>
	              <td><select name="pid">
	                  <option value="0" <if condition='$parentid eq 0'>selected</if>>顶级菜单</option>
	                  <volist name="menu" id="vo">
	                  	<option value="{$vo.id}" <if condition='$vo["id"] eq $parentid'>selected</if>>{:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;',$vo['level'])}<if condition='$vo["level"] gt 0'>├─</if>{$vo.html}{$vo.title}</option>
	                  </volist>
	                </select></td>
	            </tr>
	            <tr>
	              <td>菜单名称:</td>
	              <td><input type="text" class="input length_5" name="title" value="" id="title"></td>
	            </tr>
	            <tr>
	              <td>菜单规则:</td>
	              <td><input type="text" class="input length_5" name="name" id="name" value=""></td>
	            </tr>
	            <tr>
	              <td>菜单排序:</td>
	              <td><input type="text" class="input length_5" name="sort" id="sort" value=""></td>
	            </tr>
	            <tr>
	              <td>菜单条件:</td>
	              <td><input type="text" class="input length_5" name="condition" id="condition" value=""></td>
	            </tr>
	            <tr>
	            	<td>菜单图标：</td>
					<td>
						<input id="System_Menu_icons_input" name="icon" type="hidden" value="icons-other-cog" />
						<strong id="System_Menu_icons" style="margin-right: 10px;"><span class="tree-icon tree-file icons-other-cog"></span></strong>
						<a class="tubiao" onclick="Show_System_Menu_icons()">选择图标</a>
					</td>
	            </tr>
	            <tr>
	              <td>状态:</td>
	              <td><select name="status">
	                  <option value="1" <eq name="status" value="1">selected</eq>>显示</option>
	                  <option value="0" <eq name="status" value="0">selected</eq>>不显示</option>
	                </select>需要明显不确定的操作时建议设置为不显示，例如：删除，修改等</td>
	            </tr>
	            <tr>
	              <td>是否显示:</td>
	              <td><select name="isshow">
	                  <option value="1" <eq name="isshow" value="1">selected</eq>>显示</option>
	                  <option value="0" <eq name="isshow" value="0">selected</eq>>不显示</option>
	                </select>是否显示菜单在后台管理页面上</td>
	            </tr>
	            <tr>
	              <td>类型:</td>
	              <td><select name="type">
	                  <option value="1" selected>权限认证+菜单</option>
	                  <option value="0" >只作为菜单</option>
	                </select>
	                注意：“权限认证+菜单”表示加入后台权限管理，纯粹是菜单项请不要选择此项。</td>
	            </tr>
	          </tbody>
	        </table>
	      </div>
	      <div class="btn_wrap">
	        <div class="btn_wrap_pd">
	          <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">添加</button>
	        </div>
	      </div>
	    </form>
	  </div>
</div>
<script>
function Select_System_Menu_icons(icon){
	$("#System_Menu_icons").html('<span class="tree-icon tree-file '+icon+'"></span>');
	$("#System_Menu_icons_input").val(icon);
	layer.closeAll();
}
function Show_System_Menu_icons(){
	layer.open({
	    type: 1,
	    title: '请选择菜单图标',
	    shadeClose: true,
	    shade: 0.8,
	    offset: '100px',
	    area: ['480px', '500px'],
	    content: '正在加载图标中...' //iframe的url
	});
	$.post("{:U('SiteCom/iconsCls')}","",function(data){
		if(typeof data == 'object'){
			var content = [];
			for(x in data){
				content[x] = "<span class='tree-icon tree-file "+data[x]+"' onclick=\"Select_System_Menu_icons('"+data[x]+"')\" style='cursor:pointer;'></span>";
			}
			var ss = '<div style="padding:10px">';
				ss += content;
				ss += '</div>';
			$('.layui-layer-content').html("<div style='padding:10px;'>"+content.join(" ")+"</div>");
		} else {
			$('.layui-layer-content').html("<div style='padding:10px;'>图标加载失败，请联系管理员！</div>");
		}
	},'json').error(function(){
		$('.layui-layer-content').html("<div style='padding:10px;'>图标加载失败，请联系管理员！3秒后自动关闭...</div>");
	});

}
</script>
<script type="text/javascript">
var menudizhi = "{:U('Site/menu')}";
var checkAddMTit = "{:U('SiteCom/checkAddMTit')}";
var checkAddMenu = "{:U('SiteCom/checkAddMenu')}";
$(function(){
	jQuery.validator.addMethod("chinaese", function(value, element) {
	  var chinaese = /^[\u4e00-\u9fa5]+$/;
	  return this.optional(element) || (chinaese.test(value));
	  }, "只能输入中文");
	$('form[name=addMenu]').validate({
		errorElement : 'span',
		validClass: "success",	//非常重要
		success : function (label) {
			label.addClass('success');
		},
        rules : {
                title : {
                    required : true,
                    chinaese : true,
                    remote : {
                     url : checkAddMTit,
                     type : 'post',
                     dataType : 'json',
                     data : {
                       title : function(){
                         return $('#title').val();
                       }
                     }
                    }
                },
                name : {
                    required : true,
                    remote : {
                     url : checkAddMenu,
                     type : 'post',
                     dataType : 'json',
                     data : {
                       name : function(){
                         return $('#name').val();
                       }
                     }
                    }
                },
            },
        messages : {
                title : {
                    required : "请输入菜单名称",
                    remote : '菜单名称已存在'
                },
                name : {
                    required : "请输入菜单规则",
                    remote : '菜单规则已存在'
                },
            },
            submitHandler: function(form)
            {
            	if($('.J_ajax_submit_btn').attr("disabledSubmit")){
			        $('.J_ajax_submit_btn').text('请勿重复提交...').prop('disabled', true).addClass('disabled');
			        return false;
			    }
				$('.J_ajax_submit_btn').attr("disabledSubmit",true);
            	var param = $('form[name=addMenu]').serialize();
            	$.ajax({
					url: $('form[name=addMenu]').attr('action'),
					dataType:'json',
					type:'POST',
					data:param,
					success: function(data) {
						if (data=='-20') {
							ITENY.alert('提示','添加菜单成功,3秒后为你跳转!',1,'3000');
							setTimeout(function(){
			                    window.location.href=menudizhi;
			                },3000);
						}else if(data=='-1')
						{
							ITENY.alert('提示','菜单名称不能为空',1,'3000');
							$('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
							$('.J_ajax_submit_btn').attr("disabledSubmit",'');						}
						else if(data=='-2')
						{
							ITENY.alert('提示','菜单规则不能为空',1,'3000');
							$('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
							$('.J_ajax_submit_btn').attr("disabledSubmit",'');
						}
						else if(data=='-3')
						{
							ITENY.alert('提示','菜单名称已存在',1,'3000');
							$('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
							$('.J_ajax_submit_btn').attr("disabledSubmit",'');
						}
						else if(data=='-4')
						{
							ITENY.alert('提示','菜单规则已存在',1,'3000');
							$('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
							$('.J_ajax_submit_btn').attr("disabledSubmit",'');
						}
						else {
							ITENY.alert('提示','未知错误，请联系管理员！',1,'3000');
							$('.J_ajax_submit_btn').text('添加').removeProp('disabled').removeClass('disabled');
							$('.J_ajax_submit_btn').attr("disabledSubmit",'');
						}
					}
				});

            }

	});
});
</script>
</body>
</html>